# coding:utf-8

from gremlin_python.driver import client as cli


client = cli.Client('ws://192.168.213.37:8182/gremlin', 'g')
# client.executor.shutdown()
# print(client.executor._shutdown)
# client.close()
# client.executor.shutdown()
# print(client.executor._shutdown)
# client._get_connection().connect()
result_set=client.submitAsync("g.V()")
print(result_set.result().one())
# print(client.executor._shutdown)
# client.submit("g.addV('xxshenguocheng','user').property('name','沈国成')")
# result_set.all().result()
# result_set=client.submit("g.V('05f777de-0c0b-4557-824a-b39cec16d8ae').valueMap()")
# print(result_set.all().result())
# result_set=client.submit("g.E().in()")
# result_set.all().result()
# result_set=client.submit("g.E().out()")
# result_set.all().result()
# result_set = client.submit("g.V().outE().toList()")
# future_results = result_set.all()
# results = future_results.result()
# print(result_set)
# print(results)

# def execute_gremlin(scripts, table_name):
#     global client
#     results = []
#     scripts = '''graph = (HBaseGraph) GraphFactory.open(new HBaseGraphConfiguration().setInstanceType(HBaseGraphConfiguration.InstanceType.DISTRIBUTED).setGraphNamespace("%s").setCreateTables(true).setRegionCount(3).set("hbase.zookeeper.quorum", "192.168.213.31").set("zookeeper.znode.parent", "/hbase").setUseSchema(true).setCompressionAlgorithm("NONE"));''' % table_name + scripts
#     result_set = client.submit(scripts.encode('utf8'))
#     future_results = result_set.all()
#     results = future_results.result()
#     return results



# client = None

# def execute_gremlin(scripts):
#     global client
#     if client is None or client.executor._shutdown:
#         client = cli.Client('ws://192.168.213.37:8182/gremlin', 'g')
#     results = []
#     result_set = client.submit(scripts)
#     results = result_set.all().result()
#     return results

# b=execute_gremlin("g.V().union(id(),label(),valueMap())")
# # b=execute_gremlin("g.V('0001').bothE().dedup().union(id(),label(),valueMap(),inV().id(),outV().id())")
# # print(b)
# for i in range(int(len(b)/3)):
#     print('---------------------------------')
#     print(b[i*3])
#     print(b[i*3+1])
#     print(type(b[i*3+2]))
#     date_str='o'
    # print(b[i*3+2].items())
    # def filter_date(d):
    #     if d[0]<=date_str: return d  
    # filter_result=sorted(filter(filter_date,b[i*3+2].items()),key=lambda k:k[0],reverse=True)
    # print(filter_result)
    # break
    # if(b[i*3+2]):
    #     print(sorted(b[i*3+2].items(),key=lambda k:k[0],reverse=True)[0][0])
    #     print(sorted(b[i*3+2].items(),key=lambda k:k[0],reverse=True)[0][1][0])
    


# print('s'<='a' )